//
//  ScanMemberViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/8/18.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ScanMemberViewController.h"
#import "TradeLargeTableViewCell.h"
#import "integralListTableViewCell.h"

@interface ScanMemberViewController ()
{
  //  NSMutableArray *mMemberDetailFeaturesArray;
    NSMutableArray *memberDetailFeaturesNameArray;
    
    NSMutableArray *tradeDateArray;
    NSMutableArray *tradeStatusArray;
    NSMutableArray *tradeCodeArray;
    NSMutableArray *tradeGuideNameArray;
    NSMutableArray *tradeProductNameArray;
    NSMutableArray *tradePriceArray;
    NSMutableArray *tradeNumberArray;
    NSMutableArray *tradeWeightArray;
    
    NSUInteger _tradePageIndex;
    NSUInteger _tradeTotalCount;
    NSUInteger _tradeTotalPage;
    
    NSUInteger _integralPageIndex;
    NSUInteger _integralTotalCount;
    NSUInteger _integralTotalPage;
    
    NSMutableArray *mIntegralDetailArray;
    NSMutableArray *integralIdArray;
    NSMutableArray *integralDateArray;
    NSMutableArray *integralReasonArray;
    NSMutableArray *integralAmountArray;
    NSMutableArray *integralPriceArray;

}

@end

@implementation ScanMemberViewController
-(void)viewWillAppear:(BOOL)animated
{
    for (UIButton *button in _detail_tagView.subviews) {
        [button removeFromSuperview];
        
    }
    [self initIntegralView];
   // mMemberDetailFeaturesArray=[NSMutableArray array];
    memberDetailFeaturesNameArray=[NSMutableArray array];
    
    tradeDateArray=[NSMutableArray array];
    tradeStatusArray=[NSMutableArray array];
    tradeCodeArray=[NSMutableArray array];
    tradeGuideNameArray=[NSMutableArray array];
    tradeProductNameArray=[NSMutableArray array];
    tradePriceArray=[NSMutableArray array];
    tradeNumberArray=[NSMutableArray array];
    tradeWeightArray=[NSMutableArray array];
    [_tradeTableView reloadData];
    
    _integralButton.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _integralButton.layer.borderWidth= 1.0f;
    _integralButton.layer.cornerRadius=3;
    [_integralButton addTarget:self action:@selector(integralBtnClick) forControlEvents:UIControlEventTouchUpInside];


  [self requestMemberDetail:_memberCodeStr];
    
    _tradePageIndex=0;
    [self loadTradeNextPage:_tradePageIndex];
}
-(IBAction)scanMemberBackClick
{
    if ([self.delegate respondsToSelector:@selector(scanMemberBackClick)]) {
        
        [self.delegate scanMemberBackClick];
    }
    
}

-(void)initIntegralView
{
    mIntegralDetailArray=[NSMutableArray array];
    integralIdArray=[NSMutableArray array];
    
    integralDateArray=[NSMutableArray array];
    integralReasonArray=[NSMutableArray array];
    integralAmountArray=[NSMutableArray array];
    integralPriceArray=[NSMutableArray array];
    
    CGRect viewFrame=_integralViewContainer.frame;
    viewFrame.origin.y=768;
    _integralViewContainer.frame=viewFrame;
    
    
    [_integralAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_integralAlphaView addTarget:self action:@selector(integralAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];


}
-(void)integralAlphaViewClick
{
    [UIView animateWithDuration:0.5 animations:^{
        
        CGRect viewFrame=_integralViewContainer.frame;
        viewFrame.origin.y=768;
        _integralViewContainer.frame=viewFrame;
        
    } completion:^(BOOL finished){
        //        // if (mFeaturesArray.count==0) {
        //        [self requestTags];
        //        // }
        
    }];
    
}

-(void)integralBtnClick
{
    [integralIdArray removeAllObjects];
    [integralReasonArray removeAllObjects];
    [integralDateArray removeAllObjects];
    [integralAmountArray removeAllObjects];
    [integralPriceArray removeAllObjects];
    
    [UIView animateWithDuration:0.5 animations:^{
        
        CGRect viewFrame=_integralViewContainer.frame;
        viewFrame.origin.y=0;
        _integralViewContainer.frame=viewFrame;
        
    } completion:^(BOOL finished){
        
    }];
    
      _integralPageIndex=0;
    [self loadIntegralNextPage:_integralPageIndex];

    
}
-(void) loadIntegralNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _integralTotalCount<=integralIdArray.count)
        return;
    if(oldPageNum == 0){
        [integralIdArray removeAllObjects];
        [_integralTableView reloadData];
    }
    _integralPageIndex=oldPageNum+1;
    [self requestIntegralList: _integralPageIndex pageSize:5];
}

-(void)requestIntegralList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_memberCodeStr forKey:@"UserCode"];
        
        
        [HttpRequest requestData:@"Guide/IntegralList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            //  NSLog(@"severDataDict22===%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    _integralTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    //  _detail_integralLabel.text=[NSString stringWithFormat:@"%d",_integralTotalCount];
                    if (_integralTotalCount%5!=0) {
                        _integralTotalPage=_integralTotalCount/5+1;
                    }
                    else if (_integralTotalCount%5==0)
                    {
                        _integralTotalPage=_integralTotalCount/5;
                    }
                    mIntegralDetailArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //  NSLog(@"mMembersArray===%@",mMembersArray);
                    if ( mIntegralDetailArray.count>0) {
                        for (int i=0; i< mIntegralDetailArray.count; i++) {
                            
                            [integralIdArray addObject:[[mIntegralDetailArray objectAtIndex:i] objectForKey:@"MYID"]];
                            [integralReasonArray addObject:[[mIntegralDetailArray objectAtIndex:i] objectForKey:@"Memo"]];
                            [integralDateArray addObject:[[mIntegralDetailArray objectAtIndex:i] objectForKey:@"CreateDate"]];
                            [integralAmountArray addObject:[[mIntegralDetailArray objectAtIndex:i] objectForKey:@"Integral"] ];
                            [integralPriceArray addObject:[[mIntegralDetailArray objectAtIndex:i] objectForKey:@"Amount"] ];
                        }
                    }
                    
                    [_integralTableView reloadData];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


-(void) loadTradeNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _tradeTotalCount<=tradeCodeArray.count)
        return;
    if(oldPageNum == 0){
        [tradeCodeArray removeAllObjects];
        [_tradeTableView reloadData];
    }
    _tradePageIndex=oldPageNum+1;
    [self requestTradeList: _tradePageIndex pageSize:4];
}
-(void)requestTradeList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
       // [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:_memberCodeStr forKey:@"MemberCode"];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
       // [params setObject:_searchTextField.text forKey:@"KeyWord"];
        //   NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/MemberTransactionDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
          //  [Global hideProgressHUDInternal:self.view];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                  //  [Global hideProgressHUDInternal:self.view];
                    //   NSLog(@"tttt11====%@",severDataDict.dataDict);
                    _tradeTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    
                    if (_tradeTotalCount%4!=0) {
                        _tradeTotalPage=_tradeTotalCount/4+1;
                    }
                    else if (_tradeTotalCount%4==0)
                    {
                        _tradeTotalPage=_tradeTotalCount/4;
                    }
                    _tradePriceLabel.text=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"MemberTotal"] floatValue]];
                    NSMutableArray * mTradesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"] ];
                    // NSLog(@"mMembersArray===%@",mMembersArray);
                  //  if ( mMembersArray.count>0) {
                        for (int i=0; i< mTradesArray.count; i++) {
                            
                            [tradeCodeArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [tradeDateArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            
                            //  NSString
                            [tradeGuideNameArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [tradeProductNameArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [tradePriceArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            [tradeStatusArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [tradeNumberArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"Number"]];
                            [tradeWeightArray addObject:[[mTradesArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            
                        }
                   // }
                    //                    for (int i=0; i<memberAddressArray.count; i++) {
                    //                        NSLog(@"memberAddressArray[%d]===%@",i,[memberAddressArray objectAtIndex:i]);
                    //                    }
                    
                    [_tradeTableView reloadData];
                    
                    //  NSLog(@"_tradeViewContainer.y====%f",_tradeViewContainer.frame.origin.y);
                    
                    
                }
                else
                {
                  //  [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                     [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


-(void)requestMemberDetail:(NSString *)userCode
{
    _detail_nameAndPhoneLabel.text=@"";
   // [_detail_sexImage setImage:nil];
    _detail_gradeLabel.text=@"";
    _detail_guideNameLabel.text=@"";
    _detail_storeNameLabel.text=@"";
    _detail_addressLabel.text=@"";
    _detail_remarkView.text=@"";
    _detail_integralLabel.text=@"";
    _tradePriceLabel.text=@"";
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:userCode forKey:@"UserCode"];
        [HttpRequest requestData:@"Guide/FindMemberInf" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                    if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                   [Global hideProgressHUDInternal:self.view];
                     //  NSLog(@"345==%@",severDataDict.dataDict);
                    _detail_nameAndPhoneLabel.text=[NSString stringWithFormat:@"%@(%@)",[severDataDict.dataDict objectForKey:@"UserName"],[severDataDict.dataDict objectForKey:@"Phone"]];
                    //   NSLog(@"_detail_nameAndPhoneLabel.text==%@",_detail_nameAndPhoneLabel.text);
                    // [self resizeLabel:_detail_nameAndPhoneLabel];
                    _detail_nameAndPhoneLabel.numberOfLines = 0;
                    _detail_nameAndPhoneLabel.lineBreakMode = NSLineBreakByWordWrapping;
                    CGSize maximumLabelSize = CGSizeMake(1000, _detail_nameAndPhoneLabel.frame.size.height);
                    
                    CGSize expectSize = [_detail_nameAndPhoneLabel sizeThatFits:maximumLabelSize];
                    CGRect frame11 = CGRectMake(_detail_nameAndPhoneLabel.frame.origin.x, _detail_nameAndPhoneLabel.frame.origin.y,expectSize.width, _detail_nameAndPhoneLabel.frame.size.height );
                    _detail_nameAndPhoneLabel.frame=frame11;
                    
                    
                    CGRect frame=_detail_sexImage.frame;
                    frame.origin.x=_detail_nameAndPhoneLabel.frame.origin.x+_detail_nameAndPhoneLabel.frame.size.width;
                    _detail_sexImage.frame=frame;
                    
                    CGRect frame1=_detail_gradeTagLabel.frame;
                    frame1.origin.x=_detail_sexImage.frame.origin.x+_detail_sexImage.frame.size.width+10;
                    _detail_gradeTagLabel.frame=frame1;
                    
                    CGRect frame2=_detail_gradeLabel.frame;
                    frame2.origin.x=_detail_gradeTagLabel.frame.origin.x+_detail_gradeTagLabel.frame.size.width+2;
                    _detail_gradeLabel.frame=frame2;
                    
                    CGRect frame3=_detail_integralTagLabel.frame;
                    frame3.origin.x=_detail_gradeLabel.frame.origin.x+_detail_gradeLabel.frame.size.width+16;
                    _detail_integralTagLabel.frame=frame3;
                    
                    CGRect frame4=_integralButton.frame;
                    frame4.origin.x=_detail_integralTagLabel.frame.origin.x+_detail_integralTagLabel.frame.size.width+3;
                    _integralButton.frame=frame4;
                    

                    _detail_gradeLabel.text=[severDataDict.dataDict objectForKey:@"Grade"];
                    _detail_integralLabel.text=[NSString stringWithFormat:@"%ld",(long)[[severDataDict.dataDict objectForKey:@"Integral"] integerValue]];
                    _currentIntegralLabel.text=[NSString stringWithFormat:@"%ld",(long)[[severDataDict.dataDict objectForKey:@"Integral"] integerValue]];
                    _detail_remarkView.text=[severDataDict.dataDict objectForKey:@"Memo"];
                    _detail_guideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                    
                    [self resizeLabel:_detail_guideNameLabel];
                    CGRect frame5=_detail_storeNameTagLabel.frame;
                    frame5.origin.x=_detail_guideNameLabel.frame.origin.x+_detail_guideNameLabel.frame.size.width+10;
                    _detail_storeNameTagLabel.frame=frame5;
                    
                    CGRect frame6=_detail_storeNameLabel.frame;
                    frame6.origin.x=_detail_storeNameTagLabel.frame.origin.x+_detail_storeNameTagLabel.frame.size.width+3;
                    _detail_storeNameLabel.frame=frame6;
                    //  _detail_birthLabel.text=[severDataDict.dataDict objectForKey:@"BirthDate"];
                    _detail_storeNameLabel.text=[severDataDict.dataDict objectForKey:@"StoreName"];
                    _detail_addressLabel.text=[NSString stringWithFormat:@"%@%@%@%@",[severDataDict.dataDict objectForKey:@"ProvinceName"],[severDataDict.dataDict objectForKey:@"CityName"],[severDataDict.dataDict objectForKey:@"RegionName"],[severDataDict.dataDict objectForKey:@"Address"]];//[severDataDict.dataDict objectForKey:@"Address"];
                    //  _detail_storeNameLabel.text=[]
                    
                    //  [memberDetailFeaturesNameArray removeAllObjects];
                    
                    NSMutableArray *mMemberDetailFeaturesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mMemberDetailFeaturesArray.count; i++) {
                        [memberDetailFeaturesNameArray addObject:[[mMemberDetailFeaturesArray objectAtIndex:i] objectForKey:@"FeatureName"]];
                       // [selectFeatureCodeArray addObject:[[mMemberDetailFeaturesArray objectAtIndex:i] objectForKey:@"FeatureCode"]];
                    }
                    [self setMemberDetailTagView];
                          }
                else
                {
                    //  NSLog(@"345==%@",severDataDict.dataDict);
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                      [Global loginViewController:self noteStr:requestResultStr];  
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)setMemberDetailTagView
{
    for (int i=0; i<memberDetailFeaturesNameArray.count; i++) {
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=32;
        rect.size.width=80;
        rect.origin.x=90*(i%6);
        rect.origin.y=8+46*(i/6);
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor colorWithRed:254.0f/255.0f green:249.0f/255.0f blue:228.0f/255.0f alpha:1.0f]];
        button.layer.borderWidth=1;
        button.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
        button.layer.cornerRadius=16;
        button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [button setTitle:[memberDetailFeaturesNameArray objectAtIndex:i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        
        //[button addTarget:self action:@selector(tagButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_detail_tagView addSubview:button];
    }
    if (memberDetailFeaturesNameArray.count>6) {
        CGRect viewFrame=_detail_tagView.frame;
        viewFrame.size.height=108;
        _detail_tagView.frame=viewFrame;
    }
    else if(memberDetailFeaturesNameArray.count<6&&memberDetailFeaturesNameArray.count>0)
    {
        CGRect viewFrame=_detail_tagView.frame;
        viewFrame.size.height=49;
        _detail_tagView.frame=viewFrame;
    }
    else if(memberDetailFeaturesNameArray.count==0)
    {
        CGRect viewFrame=_detail_tagView.frame;
        viewFrame.size.height=0;
        _detail_tagView.frame=viewFrame;
    }
    
    
    CGRect viewFrame2=_memberDetailTitleView.frame;
    viewFrame2.size.height=_detail_tagView.frame.origin.y+_detail_tagView.frame.size.height;
    _memberDetailTitleView.frame=viewFrame2;
    
    CGRect viewFrame1=_detail_LastView.frame;
    viewFrame1.origin.y=_memberDetailTitleView.frame.origin.y+_memberDetailTitleView.frame.size.height;
    _detail_LastView.frame=viewFrame1;
    
    CGRect viewFrame3=_tradeViewContainer.frame;
    viewFrame3.origin.y=_detail_LastView.frame.origin.y+_detail_LastView.frame.size.height;
    _tradeViewContainer.frame=viewFrame3;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   if (tableView==_tradeTableView)
    {
        return tradeCodeArray.count;
    }
   else
   {
       return integralIdArray.count;
   }

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_tradeTableView) {
        return 120;
    }
   
    else
        return 60;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
      if (tableView==_tradeTableView)
    {
        static NSString * const  tradeIdentifier = @"tradeIdentifier";
        TradeLargeTableViewCell *cell=( TradeLargeTableViewCell *)[tableView dequeueReusableCellWithIdentifier: tradeIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TradeLargeTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        
        if (tradeCodeArray.count>0) {
            cell.codeLabel.text=[tradeCodeArray objectAtIndex:indexPath.row];
           // [self resizeLabel: cell.codeLabel];
            cell.codeLabel.numberOfLines = 0;
            cell.codeLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.codeLabel.frame.size.height);
            
            CGSize expectSize = [cell.codeLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.codeLabel.frame.origin.x, cell.codeLabel.frame.origin.y,expectSize.width, cell.codeLabel.frame.size.height );
            cell.codeLabel.frame=frame1;

        }
        if (tradeStatusArray.count>0) {
            NSString *statusStr=[tradeStatusArray objectAtIndex:indexPath.row];
            cell.statusLabel.text=[NSString stringWithFormat:@"【%@】",[tradeStatusArray objectAtIndex:indexPath.row]];
            CGRect frame=cell.statusLabel.frame;
            frame.origin.x=cell.codeLabel.frame.origin.x+cell.codeLabel.frame.size.width;
            cell.statusLabel.frame=frame;
            if ([statusStr isEqualToString:@"已结算"]) {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                
            }
            
            else
            {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                
            }
            
        }
        if (tradeGuideNameArray.count>0) {
            cell.guideNameLabel.text =[tradeGuideNameArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.guideNameLabel];
            
            cell.guideNameLabel.numberOfLines = 0;
            cell.guideNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.guideNameLabel.frame.size.height);
            
            CGSize expectSize = [cell.guideNameLabel sizeThatFits:maximumLabelSize];
            CGRect frame0 = CGRectMake(cell.guideNameLabel.frame.origin.x, cell.guideNameLabel.frame.origin.y,expectSize.width, cell.guideNameLabel.frame.size.height );
            cell.guideNameLabel.frame=frame0;

            
            CGRect frame1=cell.dateTagLabel.frame;
            frame1.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame1;
            
            CGRect frame2=cell.dateLabel.frame;
            frame2.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame2;
            
        }
        if (tradeDateArray.count>0) {
            cell.dateLabel.text=[tradeDateArray objectAtIndex:indexPath.row];
        }
        if (tradePriceArray.count>0) {
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[tradePriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (tradeNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[tradeNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (tradeWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[tradeWeightArray objectAtIndex:indexPath.row] floatValue]];
        }
        
        if (tradeProductNameArray.count>0 ) {
            nameStr=[tradeProductNameArray objectAtIndex:indexPath.row];
            if ([numberStr floatValue]>1) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            
            // cell.productNameLabel.text=[NSString stringWithFormat:@"%@/%@",nameStr,weightStr];
           // [self resizeLabel:cell.productNameLabel];
            cell.productNameLabel.numberOfLines = 0;
            cell.productNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.productNameLabel.frame.size.height);
            
            CGSize expectSize = [cell.productNameLabel sizeThatFits:maximumLabelSize];
            CGRect frame0 = CGRectMake(cell.productNameLabel.frame.origin.x, cell.productNameLabel.frame.origin.y,expectSize.width, cell.productNameLabel.frame.size.height );
            cell.productNameLabel.frame=frame0;
            

            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+15;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;
        }
        
        return cell;
        
    }
      else
      {
          static NSString * const  IntegralListIdentifier = @"IntegralListIdentifier";
          integralListTableViewCell *cell=( integralListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: IntegralListIdentifier];
          if (cell==nil) {
              NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"integralListTableViewCell" owner:self options:nil];
              cell = [array objectAtIndex:0];
          }
          NSString *integralDateStr=@"";
          NSString *integralResonStr=@"";
          NSString *integralPriceStr=@"";

          if (integralReasonArray.count>0) {
              integralResonStr=[integralReasonArray objectAtIndex:indexPath.row];
          }
          if (integralDateArray.count>0) {
              integralDateStr=[integralDateArray objectAtIndex:indexPath.row];
          }
          if (integralPriceArray.count>0) {
              integralPriceStr=[NSString stringWithFormat:@"¥%ld",(long)[[integralPriceArray objectAtIndex:indexPath.row] integerValue]];
          }
            cell.dateLabel.text=[NSString stringWithFormat:@"%@  %@  %@",integralDateStr,integralResonStr,integralPriceStr];

          if (integralAmountArray.count>0) {
              cell.integralAmountLabel.text=[NSString stringWithFormat:@"%ld",(long)[[integralAmountArray objectAtIndex:indexPath.row] integerValue]];
          }
                   if (indexPath.row == [integralIdArray count] - 1)
          {
              if (_integralPageIndex<=_integralTotalPage) {
                  //  NSLog(@"###LOADING???");
                  [self loadIntegralNextPage:_integralPageIndex];
              }
          }
          
          return cell;
      }

}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
-(void)resizeLabel:(UILabel *)aLabel
{
    aLabel.lineBreakMode =NSLineBreakByWordWrapping;
    aLabel.numberOfLines =0;
    
    NSString *contentStr=aLabel.text;
    //if (contentStr) {
    aLabel.autoresizesSubviews = YES;
    aLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    
    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:contentStr];
    aLabel.attributedText = attrStr;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    NSDictionary *attribute = @{NSFontAttributeName:aLabel.font, NSParagraphStyleAttributeName:paragraphStyle.copy};
    CGSize textSize = [aLabel.text boundingRectWithSize:CGSizeMake(1000,aLabel.frame.size.height) // 用于计算文本绘制时占据的矩形块
                                                options:NSStringDrawingUsesLineFragmentOrigin //| NSStringDrawingUsesFontLeading // 文本绘制时的附加选项
                                             attributes:attribute        // 文字的属性
                                                context:nil].size; // context上下文。包括一些信息，例如如何调整字间距以及缩放。该对象包含的信息将用于文本绘制。该参数可为nil
    CGRect frame = CGRectMake(aLabel.frame.origin.x, aLabel.frame.origin.y,textSize.width, aLabel.frame.size.height );
    aLabel.frame=frame;
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
